========================================================================= 
Log Path: ./log/log_A1.log 
Program Path: /Users/james/Dropbox/Research/Diplomacy/Replication/A1.R 
Working Directory: /Users/james/Dropbox/Research/Diplomacy/Replication 
User Name: james 
R Version: 4.1.2 (2021-11-01) 
Machine: Jamess-MacBook-Air.local x86_64 
[1] "Operating System: Darwin 20.6.0 Darwin Kernel Version 20.6.0: Tue Feb 22 21:10:41 PST 2022; root:xnu-7195.141.26~1/RELEASE_X86_64"
[1] "Base Packages: stats graphics grDevices utils datasets methods base\nOther Packages: logr_1.3.0 gridExtra_2.3 ggpubr_0.4.0 estimatr_0.30.2 coefplot_1.2.7\n                rio_0.5.29 xtable_1.8-4 forcats_0.5.1 stringr_1.4.0 dplyr_1.0.7\n                purrr_0.3.4 readr_1.4.0 tidyr_1.1.3 tibble_3.1.2 ggplot2_3.3.6\n                tidyverse_1.3.1 "
Log Start Time: 2022-06-18 13:20:11 
========================================================================= 

> library(logr)
> log_open("log_A1.log")
> log_code()
> ####################
> #REPLICATION FILES: APPENDIX 1
> #Article: "When Does Online Public Diplomacy Succeed? Evidence from China's ‘Wolf Warrior’ Diplomats"
> #Authors: Daniel Mattingly and James Sundquist
> #This Version: June 18, 2022
> 
> 
> ####################
> #Description: Running this script will create the tables presented in Appendix 1 of the article.
> #The script was written with R version 4.1.2
> #It was created and tested on Mac OS X (11.6.5).
> ####################
> 
> 
> # Load required packages
> library(tidyverse)
> library(xtable)
> library(rio)
> library(coefplot)
> 
> # Set working directory
> setwd("~/Dropbox/Research/Diplomacy/Replication")
> 
> #Load data
> pooled <- import("twitter_diplomacy_data.csv")
> # Ensure levels of treatment variable appear in proper order
> pooled$Treatment <- factor(pooled$Treatment, levels = c("control", "prochina", "antius"))
> pooled$t_ <- pooled$Treatment
> 
> 
> ###
> # A.1 Descriptive Statistics
> ##
> 
> # Renaming and coarsening covariates
> pooled <- pooled %>% dplyr::rename(Female = gender, Age = age_category, conservative = left_right,
>                             College = education, knowledgable = china_knowledge)
> pooled$Female <- if_else(pooled$Female == "Female", 1, 0)
> pooled$Under40 <- recode(pooled$Age, `18-24` = 1, `25-29` = 1, `30-39` = 1, `40-49` = 0,
>                      `50-59` = 0, `60-69` = 0, `70 or older` = 0)
> pooled$College <- if_else(pooled$College == "Graduated from college" | pooled$College == "Obtained a professional degree beyond a college degree",
>                           1, 0)
> pooled$stance <- recode(pooled$hawk_dove, `Ally` = "dove", `Partner` = "dove", `None of these words are a good fit` = "neither",
>                      `Rival` = "hawk", `Enemy` = "hawk")
> pooled$Hawk <- if_else(pooled$stance == "hawk", 1, 0)
> pooled$Dove <- if_else(pooled$stance == "dove", 1, 0)
> pooled <- pooled %>% mutate(knowledgable = if_else(knowledgable == "Hu Jintao", 1, 0))
> pooled$Extreme_left <- if_else(pooled$conservative == 1, 1, 0)
> pooled$Extreme_right <- if_else(pooled$conservative == 7, 1, 0)
> 
> myvars <- pooled %>% select(Under40, Female, College, Dove, Hawk, Extreme_left, Extreme_right)
> myvars <- myvars %>% pivot_longer(cols = everything(), names_to = "Statistic")
> 
> # Create columns of table
> my_n <- myvars %>% group_by(Statistic) %>% summarise(N = sum(!is.na(value)))
> my_mean <-myvars %>% group_by(Statistic) %>% summarise(Mean = mean(value, na.rm = TRUE))
> my_sd <-myvars %>% group_by(Statistic) %>% summarise(`St. Dev.` = sd(value, na.rm = TRUE))
> my_min <-myvars %>% group_by(Statistic) %>% summarise(Min = min(value, na.rm = TRUE))
> my_max <-myvars %>% group_by(Statistic) %>% summarise(Max = max(value, na.rm = TRUE))
> 
> # Join columns together
> summary_stats <- my_n %>% left_join(my_mean) %>%
>                           left_join(my_sd) %>% 
>                           left_join(my_min) %>% 
>                           left_join(my_max)
> # Produce table
> a1 <- print(xtable(summary_stats))
> write(a1, file = "TableA1.tex")
> 
> log_close()
> 

========================================================================= 
Log End Time: 2022-06-18 13:20:11 
Log Elapsed Time: 0 00:00:00 
========================================================================= 
